<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>随机点名</title>
    <style>
        #content {
            width: 600px;
            height: 400px;
            background: #000;
            margin: 100px auto;
            text-align: center;
            position: relative;
            line-height: 300px;
            color: dodgerblue;
            font-size: 70px;
        }

        #btn1 {
            background: #ccc;
            width: 180px;
            height: 80px;
            font-size: 30px;
            color: #f40;
            border-radius: 12px;
            position: absolute;
            bottom: 30px;
            left: 50%;
            margin-left: -90px;

        }
    </style>
</head>

<body>
    <div id="content">
        <span id="span1">
            点击开始
        </span>
        <input type="button" value="start" id="btn1">

    </div>

    <script>
        // 点击start后按钮本身文字变成end ，span1中可以随机显示某一个名字，点击end 可以按钮本身文字变为开始 span1中显示具体名字
        // 随机数数组
        let student = ["张三", "李四", "王五", "李大锤", "张三1", "李四1", "王五1", "李大锤1", "张三2", "李四3", "王五4", "李大锤5"]
        let span = document.getElementsByTagName("span")[0];
        function myRandom(min, max) {
            return parseInt(Math.random() * (max - min + 1)) + min;
        }
        let flag = true
        let timer;
        document.getElementById("btn1").onclick = function () {

            let that = this;
            if (flag) {
                that.value = `end`;
                flag = !flag;
                timer = setInterval(function () {
                    span.innerHTML = `${student[myRandom(0, student.length - 1)]}`
                }, 50)
            } else {
                that.value = `start`;
                flag = !flag;
                clearInterval(timer);
            }
        }

    </script>
</body>

</html>